package test;

/*
 * Author: JacksonCoder
 * FileName: StringOperation
 * Version: 1.0.0
 * Date: 2025/5/14
 */

import java.util.Arrays;
import java.util.List;

public class StringOperation {

    public static void main(String[] args) {
        String numberStr = "123";
        try {
            int number = Integer.parseInt(numberStr);
            System.out.println("转化后的值: " + number);
        } catch (NumberFormatException e) {
            System.out.println("输入的数字不是一个有效的数字！");
        }

        String listStr = "apple,orange,melon";
        List<String> list = Arrays.asList(listStr.split(","));
        System.out.println("转化后的list : " + list);

        String arrayStr = "1,2,3,4,5";
        String[] strArray = arrayStr.split(",");
        // System.out.println(Arrays.toString(strArray));
        int[] intArray = new int[strArray.length];

        for(int i =0; i < strArray.length; i++){
            intArray[i] = Integer.parseInt(strArray[i]);
        }

        System.out.println("转化后的 int[] 数组:");
        for(int num: intArray){
            System.out.print(num + " ");
        }
    }

}
